package com.skt.common_hr.medicalmoney_sac.model
{
	import com.skt.common_hr.medicalmoney_sac.MedicalMoneyFacade;

	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	import org.puremvc.as3.multicore.patterns.proxy.Proxy;

	public class ApprovalProxy extends Proxy
	{
		public static const NAME:String = "CongMoneyProxy";
		public var templateHTML:String;

		private var loader:URLLoader = new URLLoader();

		public function ApprovalProxy(data:Object=null)
		{
			super(NAME, data);
		}

		/**
		 * data load를 수행
		 * 		- 조회버튼클릭
		 *
		 * @param pernr GWAREKEY
		 * @return void
		 */
		public function loadTemplate():void
		{
			var request:URLRequest = new URLRequest("assets/doc/congmoney.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
				facade.sendNotification(MedicalMoneyFacade.LOAD_TEMPLATE_FAILED, this);
            }
		}

		private function templateResult(event:Event):void
		{
			templateHTML = loader.data;
			facade.sendNotification(MedicalMoneyFacade.LOAD_TEMPLATE_COMPLETE, this);
		}

		private function ioErrorHandler(event:IOErrorEvent):void
		{
			facade.sendNotification(MedicalMoneyFacade.LOAD_TEMPLATE_FAILED, this);
		}
	}
}